<template>
	<!-- 我的推广码 -->
	<view style="height: 100vh;overflow: hidden;">
		<view class="cu-bar" style="position: fixed;z-index: 2;">
			<view class="action" :style="{paddingTop:h + 5 +'px' }">
				<text class="cuIcon-back" style="color: #fff;" @click="back"></text>
			</view>
		</view>
		<view class="ercode">
			<image src="/static/bg.png" mode="" class="image"></image>
			<view class="img_div">
				<!-- 代理 -->
				<image src="/static/dl.png" mode="" v-if="user.is_agent == 1"></image>
				<!-- 普通 -->
				<image src="/static/pt.png" mode="" v-else></image>
				<view class="main bg-white">
					<view class="aycode">
						<ayQrcode ref="qrcode5" :modal="modal_qr" qrcode_id="qrcode5" :url="URL" @hideQrcode="hideQrcode" :height="180" :width="180" />
					</view>
					<view class="s"></view>
					<view class="text flex-c">我的专属邀请码</view>
					<view class="code flex-c">{{code}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import ayQrcode from "@/components/ay-qrcode/ay-qrcode.vue"
	export default {
		components: {
			ayQrcode,
		},
		data() {
			return {
				h:'',
				user:'',
				modal_qr: false,
				code:0,
				isshow:0,
				URL:'https://guizhouchenxun.com/mini/extension/?id=',
			};
		},
		onLoad() {
			if(uni.getStorageSync('code') == ''){
				this.code = Math.floor(Math.random() * 999999);
				uni.setStorageSync('code',this.code)
			}else{
				this.code = uni.getStorageSync('code')
			}
			this.$api.user().then(res=>{
				this.user = res.data
				this.URL += this.user.id
				setTimeout(()=>{
					this.$refs.qrcode5.crtQrCode()
				},50)
			})
			uni.getStorage({
				key:'height',
				success:(res)=>{
					this.h = res.data
				}
			})
		},
		onShareAppMessage(res) {
		    if (res.from === 'button') {// 来自页面内分享按钮
		      console.log(res.target)
		    }
		    return {
		      title: '快来和我一起购物返佣金',
		      path: 'pages/tabbar/index?id='+this.user.id+'&fx=1',
		    }
		},
		methods:{
			back(){
				uni.navigateBack()
			},
			handleshow(i){
				this.isshow = !this.isshow
			},
			handleitem(i){
				if(i == 1){
					this.iscode = !this.iscode
					let _this = this
					_this.modal_qr = true
					setTimeout(()=>{
						_this.$refs.qrcode5.crtQrCode()
					}, 50)
				}
			},
			// handlecopy(){
			// 	uni.setClipboardData({
			// 		data:this.URL,
			// 		success(res) {
			// 			console.log('复制成功');
			// 		}
			// 	})
			// }
		}
	}
</script>

<style lang="scss">
.ercode{
	.image{
		width: 100%;
		height: 100vh;
		position: absolute;
	}
	.img_div{
		position: absolute;top: 0;left: 0;
		width: 100%;
		height: 100vh;
		image{
			width: 700rpx;height: 140rpx;
			margin-left: 20rpx;
			margin-top: 205rpx;
			margin-bottom: 49rpx;
		}
		.main{
			width: 560rpx;
			height: 800rpx;
			margin: auto;
			padding-top: 100rpx;
			border-radius: 20rpx;
			.aycode{
				width: 360rpx;height: 360rpx;
				margin: auto;
			}
			.s{
				margin-top: 76rpx;
				border: 2rpx dashed #E6E6E6;
			}
			.text{
				color: #999;
				font-size: 24rpx;
				margin-top: 40rpx;
				margin-bottom: 50rpx;
			}
			.code{
				width: 280rpx;
				height: 80rpx;
				margin: auto;
				color: #333;
				font-size: 48rpx;
				background: #E6E6E6;
				border-radius: 40rpx;
			}
		}
	}
}

</style>
